<?php

namespace app\admin\controller;
use think\Db;

//充值管理
class Recharge extends Common{

	public function index(){
		return $this->fetch();
	}


	public function dataList(){
		$limit = request()->param('limit')?:20;
		$username   = request()->param('username');
		$phone   = request()->param('phone');
		$uid   = request()->param('uid');
		$coin_name   = request()->param('coin_name');
		$start_time = request()->param('start_time');
		$end_time   = request()->param('end_time');
		$where      = '1=1';
		if ($username != '') {
            $where .= ' and u.username like \'%' . $username . '%\'';
        }
        if ($phone != '') {
            $where .= ' and u.phone='.$phone;
        }
        if ($uid != '') {
            $where .= ' and b.uid='.$uid;
        }
        if ($coin_name != '') {
            $where .= ' and c.name like \'%' . $coin_name . '%\'';
        }
        if($start_time != '') {
            $where .= ' and t.date>="'.$start_time.'"';
        }
		if($end_time != '') {
            $where .= ' and t.date<="'.$end_time.'"';
        }
		$time = time();		
		$dtime = $time-60*10;		
		$where .= ' and b.date<='.$dtime;
		$data  = Db::table('tp_recharge_record')
				->alias('b')
				->join('tp_user u','u.id = b.uid','LEFT')
				->join('tp_coin c','c.id = b.cid','LEFT')
				->where($where)
				->order('t.id desc')
				->field('b.*,u.username,u.phone,c.name coin_name,b.date')
				->paginate($limit);
		$data = $data->toArray();
		if(empty($data['data'])){
			$data['data']  = Db::table('tp_recharge_record')
				->alias('b')
				->join('tp_user u','u.id = b.uid','LEFT')
				->join('tp_coin c','c.id = b.cid','LEFT')
				->where($where)
				->order('t.id desc')
				->field('b.*,u.username,u.phone,c.name coin_name,b.date')
				->page(1)
				->limit($limit)
				->select();		
		}
		return $this->tableData($data);
	}
}